package org.opens.mybatisplus.controller;

import com.google.common.collect.Maps;
import org.opens.mybatisplus.pojo.EnumObj;
import org.opens.mybatisplus.service.EnumObjService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping(value = "/api")
public class EnumObjController {

    @Autowired
    private EnumObjService enumObjService;

    @RequestMapping(value = "/v1/enum", method = RequestMethod.GET)
    public Map<String, Object> findById(
            @RequestParam(value = "id", required = true) Integer id
    ) {
        Map<String, Object> result = Maps.newHashMap();
        result.put("code", 200);
        result.put("data", enumObjService.findById(id));
        return result;
    }

    @RequestMapping(value = "/v1/enum", method = RequestMethod.POST)
    public Map<String, Object> save(
            @RequestBody EnumObj enumObj
    ) {
        Map<String, Object> result = Maps.newHashMap();
        System.out.println(enumObj);
        enumObjService.save(enumObj);
        result.put("code", 200);
        result.put("message", "保存成功");
        return result;
    }

}
